package com.ruoyi.procurement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurement.domain.PsReportingLosses;
import com.ruoyi.procurement.service.IPsReportingLossesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报损记录Controller
 * 
 * @author ruoyi
 * @date 2023-10-11
 */
@Api("报损记录")
@RestController
@RequestMapping("/procurement-system/losses")
public class PsReportingLossesController extends BaseController
{
    @Autowired
    private IPsReportingLossesService psReportingLossesService;

    /**
     * 查询报损记录列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:list')")
    @GetMapping("/list")
    @ApiOperation("查询报损记录列表")
    public TableDataInfo list(PsReportingLosses psReportingLosses)
    {
        startPage();
        List<PsReportingLosses> list = psReportingLossesService.selectPsReportingLossesList(psReportingLosses);
        return getDataTable(list);
    }

    /**
     * 导出报损记录列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:export')")
    @Log(title = "报损记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsReportingLosses psReportingLosses)
    {
        List<PsReportingLosses> list = psReportingLossesService.selectPsReportingLossesList(psReportingLosses);
        ExcelUtil<PsReportingLosses> util = new ExcelUtil<PsReportingLosses>(PsReportingLosses.class);
        util.exportExcel(response, list, "报损记录数据");
    }

    /**
     * 获取报损记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(psReportingLossesService.selectPsReportingLossesById(id));
    }

    /**
     * 新增报损记录
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:add')")
    @Log(title = "报损记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PsReportingLosses psReportingLosses)
    {
        return toAjax(psReportingLossesService.insertPsReportingLosses(psReportingLosses));
    }

    /**
     * 修改报损记录
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:edit')")
    @Log(title = "报损记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsReportingLosses psReportingLosses)
    {
        return toAjax(psReportingLossesService.updatePsReportingLosses(psReportingLosses));
    }

    /**
     * 删除报损记录
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:losses:remove')")
    @Log(title = "报损记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(psReportingLossesService.deletePsReportingLossesByIds(ids));
    }
}
